package com.goodving.guli.bt.profile.scale;

import com.goodving.guli.view.BitmapDescriptorFactory;
import com.goodving.guli.view.C3657a;

import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.Date;

/**
 * Created by Administrator on 2015/11/25 0025.
 */
public class ScaleWeightInfo { // C3925e
    public static final String TAG = ScaleWeightInfo.class.getSimpleName();
    public static float f19750b = 0.0f;
    public static float f19751c = 0.0f;
    public static final String WEIGHTADVDATA_KEY = "WEIGHTADVDATA_KEY";
    public static final String WEIGHTADVDATA_KEY_MAX = "WEIGHTADVDATA_KEY_MAX";
    public static final String WEIGHTADVDATA_KEY_VALUE = "WEIGHTADVDATA_KEY_VALUE";
    public static final String WEIGHTADVDATA_KEY_UNIT = "WEIGHTADVDATA_KEY_UNIT";
    public static final String WEIGHTADVDATA_KEY_BMI = "WEIGHTADVDATA_KEY_BMI";
    public static final String WEIGHTADVDATA_KEY_TIMESTAMP = "WEIGHTADVDATA_KEY_TIMESTAMP";
    public static final int f19758j = 0;
    public static final int f19759k = 16;
    public static final int f19760l = 1;
    public static int f19761m;
    public static int stable;
    public static int f19763o;
    public static int finish;
    private boolean isFinish;
    private int unitType;
    private float value;
    private float f19768s;
    private long date;
    private float valueKg;
    private float f19771v;
    private String f19772w;
    private boolean isStable;
    private boolean isHistory;
    private boolean isMeasurement;

    static {
        f19750b = BitmapDescriptorFactory.HUE_MAGENTA;
        f19751c = 65520.0f;
        f19761m = 17;
        stable = 0x20;
        f19763o = 0x40;
        finish = 0x80;
    }

    public ScaleWeightInfo() {
        this.unitType = -1;
        this.value = -1.0f;
        this.f19768s = -1.0f;
        this.date = -1;
        this.valueKg = -1.0f;
        this.f19771v = -1.0f;
        this.f19772w = C3657a.f18328f;
        this.isStable = false;
        this.isHistory = false;
        this.isMeasurement = false;
        this.isFinish = false;
    }

    public ScaleWeightInfo(int i, float f, long j, boolean z, boolean z2, boolean z3, boolean z4) {
        this.unitType = -1;
        this.value = -1.0f;
        this.f19768s = -1.0f;
        this.date = -1;
        this.valueKg = -1.0f;
        this.f19771v = -1.0f;
        this.f19772w = C3657a.f18328f;
        this.isStable = false;
        this.isHistory = false;
        this.isMeasurement = false;
        this.isFinish = false;
        this.unitType = i;
        this.value = f;
        this.date = j;
        this.isStable = z;
        this.isMeasurement = z2;
        this.isHistory = z3;
        this.isFinish = z4;
        m25480o();
    }

    public static float m25475a(float f, int i) {
        return new BigDecimal((double) f).setScale(i, 4).floatValue();
    }

    public static float m25476a(float f, int i, int i2) {
        switch (i) {
            case f19758j /*0*/:
                switch (i2) {
                    case f19758j /*0*/:
                        return f;
                    case f19760l /*1*/:
                        return ScaleWeightInfo.m25475a(2.20462f * f, 2);
                    case f19759k /*16*/:
                        return f * 2.0f;
                    default:
                        return f;
                }
            case f19760l /*1*/:
                switch (i2) {
                    case f19758j /*0*/:
                        return ScaleWeightInfo.m25475a(0.45359f * f, 2);
                    case f19760l /*1*/:
                        return f;
                    case f19759k /*16*/:
                        return ScaleWeightInfo.m25475a(0.90718f * f, 2);
                    default:
                        return 0.0f;
                }
            case f19759k /*16*/:
                switch (i2) {
                    case f19758j /*0*/:
                        return f / 2.0f;
                    case f19760l /*1*/:
                        return ScaleWeightInfo.m25475a(1.10231f * f, 2);
                    case f19759k /*16*/:
                        return f;
                    default:
                        return 0.0f;
                }
            default:
                return f;
        }
    }

    public static float m25477b(float f, int i) {
        return ScaleWeightInfo.m25476a(f, i, f19758j);
    }

    public static float m25478b(int i) {
        return i == 0 ? 150.0f : i == f19759k ? BitmapDescriptorFactory.HUE_MAGENTA : i == f19760l ? 331.1f : 150.0f;
    }

    public static ScaleWeightInfo m25479b(String str) {
        ScaleWeightInfo scaleWeightInfo = new ScaleWeightInfo();
        try {
            JSONObject jSONObject = new JSONObject(str);
            scaleWeightInfo.f19771v = (float) jSONObject.optDouble(WEIGHTADVDATA_KEY_MAX);
            scaleWeightInfo.value = (float) jSONObject.optDouble(WEIGHTADVDATA_KEY_VALUE);
            scaleWeightInfo.unitType = jSONObject.optInt(WEIGHTADVDATA_KEY_UNIT);
            scaleWeightInfo.f19768s = (float) jSONObject.optDouble(WEIGHTADVDATA_KEY_BMI);
            scaleWeightInfo.date = jSONObject.optLong(WEIGHTADVDATA_KEY_TIMESTAMP);
        } catch (Exception e) {
        }
        return scaleWeightInfo;
    }

    private void m25480o() {
        this.valueKg = ScaleWeightInfo.m25477b(this.value, this.unitType);
        this.f19771v = ScaleWeightInfo.m25478b(this.unitType);
    }

    public String m25481a() {
        return this.f19772w;
    }

    public void m25482a(float f) {
        this.f19768s = f;
    }

    public void setUnitType(int i) { // m25483a
        this.unitType = i;
        m25480o();
    }

    public void setDate(long j) { // m25484a
        this.date = j;
    }

    public void m25485a(String str) {
        this.f19772w = str;
    }

    public void setStable(boolean z) {
        this.isStable = z;
    }

    public float m25487b() {
        return this.f19771v;
    }

    public void m25488b(float f) {
        this.value = f;
        m25480o();
    }

    public void setFinish(boolean z) { // m25489b
        this.isFinish = z;
    }

    public void m25490c(float f) {
        this.valueKg = f;
    }

    public void m25491c(boolean z) {
        this.isHistory = z;
    }

    public boolean m25492c() {
        return this.isMeasurement;
    }

    public boolean isFinish() { // m25493d
        return this.isFinish;
    }

    public long m25494e() {
        return this.date;
    }

    public boolean isStable() { // m25495f
        return this.isStable;
    }

    public boolean m25496g() {
        return this.isHistory;
    }

    public int m25497h() {
        return this.unitType;
    }

    public float m25498i() {
        return this.f19768s;
    }

    public float m25499j() {
        return this.value;
    }

    public float m25500k() {
        return this.valueKg;
    }

    public boolean m25501l() {
        return (this.unitType == 0 || this.unitType == f19759k || this.unitType == f19760l) && this.value > 0.0f && this.value <= this.f19771v;
    }

    public boolean m25502m() {
        return this.value == f19751c;
    }

    public String m25503n() {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(WEIGHTADVDATA_KEY_MAX, (double) this.f19771v);
            jSONObject.put(WEIGHTADVDATA_KEY_VALUE, (double) this.value);
            jSONObject.put(WEIGHTADVDATA_KEY_UNIT, this.unitType);
            jSONObject.put(WEIGHTADVDATA_KEY_BMI, (double) this.f19768s);
            jSONObject.put(WEIGHTADVDATA_KEY_TIMESTAMP, this.date);
        } catch (Exception e) {
        }
        GuliLog.tracePrintInfo(TAG, "WeightAdvData toString " + jSONObject.toString());
        return jSONObject.toString();
    }

    public String toString() {
        return "<unitType:" + this.unitType + ",value:" + this.value + ",valueKg:" + this.valueKg + ",date:" + new Date(this.date).toString() + ",isMeasurement:" + this.isMeasurement + ",isStable:" + this.isStable + ",isHistory:" + this.isHistory + ",isFinish:" + this.isFinish + ">";
    }
}

